/**
 *  The program controller
 */

app.controller('programController', function ($scope) {
    var activeOne = "thursday";
    var myScroller;
    myScroller = new IScroll('#wrapper', {
        eventPassthrough: true,
        scrollX: true,
        scrollY: false,
        preventDefault: false,
        startX: smallestMarginLeft("thursday")
    }); 
    
    function smallestMarginLeft(divId){
        var elm = document.getElementById(divId);
        var elementArray = elm.getElementsByClassName('timeline-event');
        var smallestMargin = 2000;
        for(var i = 0; i < elementArray.length; i++){
            if(parseInt(elementArray[i].style.marginLeft, 10) < smallestMargin){
                smallestMargin = parseInt(elementArray[i].style.marginLeft, 10);
            }
        }
        return smallestMargin * -1;
    };
    
    $scope.setActive = function(dayName){
        activeOne = dayName;
        myScroller.scrollTo(smallestMarginLeft(dayName), 0, 500, IScroll.utils.ease.elastic);
    };
    $scope.isActive = function(dayName){
        return activeOne === dayName;
    };
  
});